﻿<?php
require_once("models/SinhVien.php");
require_once("models/CoVanHocTap.php");
require_once("models/HoiDongKhoa.php");

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
	$user = $_POST['cboNguoiDung'];
	
	if ($user == "SV")  { $user = new SinhVien(); }
	else if ($user == "CVHT") $user = new CoVanHocTap();
	else if ($user == "HDK") $user = new HoiDongKhoa();
	else $user = NULL;
	
	if (isset($_POST['txtmaso']) && isset($_POST['txtmatkhau'])){
		$user->setMaSo(trim($_POST['txtmaso']));
		$user->setMatKhau(md5(trim($_POST['txtmatkhau'])));	
		
		if ($user->kiemTra() != 0) {
			$user->layThongTinNguoiDung();
			$_SESSION['login'] = 1;
			$_SESSION['user'] = $user;
			header("Location: index.php");
		} else {
			echo "<script language='javascript'>alert('Tên đăng nhập hoặc mật khẩu không đúng.');"
				 . "window.location = 'index.php';</script>";
		}

	}
} else include "views/DangNhap.php";

?>
